package com.yl.danmo.controller;


import com.yl.common.core.utils.poi.ExcelUtil;
import com.yl.common.core.web.controller.BaseController;
import com.yl.common.core.web.domain.AjaxResult;
import com.yl.common.core.web.page.TableDataInfo;
import com.yl.common.log.annotation.Log;
import com.yl.common.log.enums.BusinessType;
import com.yl.common.security.annotation.RequiresPermissions;
import com.yl.danmo.domain.DanmoPersonPosition;
import com.yl.danmo.service.IDanmoPersonPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员职位关联Controller
 * 
 * @author yl
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/personPosition")
public class DanmoPersonPositionController extends BaseController
{
    @Autowired
    private IDanmoPersonPositionService danmoPersonPositionService;

    /**
     * 查询会员职位关联列表
     */
    @RequiresPermissions("system:personPosition:list")
    @GetMapping("/list")
    public TableDataInfo list(DanmoPersonPosition danmoPersonPosition)
    {
        startPage();
        List<DanmoPersonPosition> list = danmoPersonPositionService.selectDanmoPersonPositionList(danmoPersonPosition);
        return getDataTable(list);
    }

    /**
     * 导出会员职位关联列表
     */
    @RequiresPermissions("system:personPosition:export")
    @Log(title = "会员职位关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoPersonPosition danmoPersonPosition)
    {
        List<DanmoPersonPosition> list = danmoPersonPositionService.selectDanmoPersonPositionList(danmoPersonPosition);
        ExcelUtil<DanmoPersonPosition> util = new ExcelUtil<DanmoPersonPosition>(DanmoPersonPosition.class);
        util.exportExcel(response, list, "会员职位关联数据");
    }

    /**
     * 获取会员职位关联详细信息
     */
    @RequiresPermissions("system:personPosition:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(danmoPersonPositionService.selectDanmoPersonPositionById(id));
    }

    /**
     * 新增会员职位关联
     */
    @RequiresPermissions("system:personPosition:add")
    @Log(title = "会员职位关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DanmoPersonPosition danmoPersonPosition)
    {
        return toAjax(danmoPersonPositionService.insertDanmoPersonPosition(danmoPersonPosition));
    }

    /**
     * 修改会员职位关联
     */
    @RequiresPermissions("system:personPosition:edit")
    @Log(title = "会员职位关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DanmoPersonPosition danmoPersonPosition)
    {
        return toAjax(danmoPersonPositionService.updateDanmoPersonPosition(danmoPersonPosition));
    }

    /**
     * 删除会员职位关联
     */
    @RequiresPermissions("system:personPosition:remove")
    @Log(title = "会员职位关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoPersonPositionService.deleteDanmoPersonPositionByIds(ids));
    }
}
